package com.base.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.base.comm.CommContent;
import com.base.po.voip.Adversiments;
import com.base.service.AdversimentsService;
import com.base.service.LogsService;
import com.base.utils.IP;

/**
 * 修改轮播广告信息服务端
 * 
 * @author f 优化日期：10-16
 *
 */
@Controller
@RequestMapping("/admin")
public class CarouselUpdateController {

	@Autowired
	private LogsService logsService;// 日志Service
	@Autowired
	private AdversimentsService adversimentsService; // 轮播广告Service

	// 修改轮播信息
	@RequestMapping(value = "/carousel_do_update", method = RequestMethod.POST)
	public @ResponseBody int doUpdate(HttpServletRequest request, Adversiments adversiments) throws Exception {
		HttpSession session = request.getSession(false); // 获取session
		if (session == null) {
			return -1;
		}
		Object obj_id = session.getAttribute("adminUserId"); // 登录ID
		Object obj_name = session.getAttribute("userNick"); // 登录名称
		if (obj_id == null || obj_name == null) {
			return -1;
		}
		logsService.insert(CommContent.TYPE_UPDATE, CommContent.LOGS_UPDATE + "轮播广告信息", (String) obj_name, true,
				IP.getIpAddr(request));
		return adversimentsService.updateByPrimaryKeySelective(adversiments); // 修改
	}
}
